<?php 
	class models_loaihang extends connect{
		function listLoaiHang(){
			$sql = "SELECT MaLH,MaCL,TenLH
					FROM loaihang";
			$this->query_db($sql);
			return $this->fetchAll();
		}
		function tongsodong()
		{
			$sql="SELECT * from loaihang";
			$this->query_db($sql);
			return $this->totalRow();
	
		}
		function danhsachlh($start,$limit){
			$sql = "SELECT MaLH,MaCL,TenLH
					FROM loaihang 
					LIMIT $start,$limit";
			$this->query_db($sql);
			return $this->fetchAll();
		}
			
				
		function addLoaiHang($MaCL,$TenLH){
			$sql = "INSERT INTO loaihang VALUES ('','$MaCL','$TenLH')";
			$this->query_db($sql);
			
		}
		
		function delLoaiHang($intMa){
			$sql = "DELETE
					FROM loaihang
					WHERE MaLH = '$intMa'";
			$this->query_db($sql);	
		}
		function getLoaiHang($intMa)
		{
			$sql = "SELECT MaCL, MaLH, TenLH
					FROM loaihang 
					WHERE MaLH = '$intMa'";
			
			$this->query_db($sql);
			return $this->fetchOne();
		}
		function _getloaihang($intMa)
		{
			$sql = "SELECT MaCL, MaLH, TenLH
					FROM loaihang 
					WHERE MaCL = '$intMa'";
			
			$this->query_db($sql);
			return $this->fetchAll();
		}
	
	
		
		function updateLoaiHang($MaCL,$TenLH,$ma)
		{
			$sql ="	UPDATE loaihang
					SET 
						MaCL='$MaCL', 
						TenLH = '$TenLH'
					WHERE MaLH = '$ma'";
			$this->query_db($sql);
		}
		
		function _findlh($value)
		{
			$sql = "SELECT MaLH,MaCL,TenLH
			FROM loaihang
			WHERE TenLH LIKE '%$value%'";
			$this->query_db($sql);
			return $this->fetchAll();
		}
	
			
	}
class pagerlh{ 
    function findstart($limit) 
    { 
        if ((!isset($_GET['page'])) || ($_GET['page']=="1")) 
        { 
            $start=0; 
            $_GET['page']=1; 
        } 
        else 
        { 
            $start=($_GET['page']-1)*$limit; 
        } 
        return $start; 
    } 
    function findpages($count,$limit) 
    { 
        $pages=(($count % $limit)==0) ? $count / $limit : floor($count / $limit)+1; 
        return $pages; 
    } 
    function pagelist($curpage , $pages) 
    { 
        $page_list=""; 
       
        if(($curpage !=1) && ($curpage)) 
        { 
            $page_list .="<a href=\"".$_SERVER['PHP_SELF']."?mod=loaihang"."&page=1\" title=\"Trang đầu\"> << </a> "; 
        } 
        if(($curpage-1) > 0) 
        { 
           	$page_list .="<a href=\"".$_SERVER['PHP_SELF']."?mod=loaihang"."&page=".($curpage-1)."\" title=\"Trang trước\"> < </a>"; 	
        } 
        for ($i=1; $i<=$pages; $i++) 
        { 
            if($i==$curpage) 
            { 
                $page_list .="<b>".$i."</b>"; 
            } 
            else 
            { 
                $page_list .="<a href=\"".$_SERVER['PHP_SELF']."?mod=loaihang"."&page=".$i."\" title=\"Trang".$i."\">".$i."</a>"; 
            } 
            $page_list .=" "; 
        } 
        if (($curpage+1) <=$pages) 
        { 
			$page_list .="<a href=\"".$_SERVER['PHP_SELF']."?mod=loaihang"."&page=".($curpage+1)."\" title=\"Trang sau\"> > </a>"; 	
		}
		if(($curpage !=$pages) && ($pages != 0)){
		
            $page_list .="<a href=\"".$_SERVER['PHP_SELF']."?mod=loaihang"."&page=".$pages."\" title=\"Trang cuối\"> >> </a>"; 
        } 
		
        $page_list .="</td>\n\n"; 
        return $page_list; 
    } 
    function nextprev($curpage,$pages) 
    { 
        $next_prev=""; 
        if(($curpage-1)<=0) 
        { 
            $next_prev .="Ve trang truoc";            
        } 
            else 
            { 
                $next_prev .="<a href=\"".$_SERVER['PHP_SELF']."?mod=loaihang"."&page=".($curpage-1)."\"> Trang trước</a>"; 
            } 
            $next_prev .=" || "; 
            if (($curpage+1) > $pages) 
            { 
                $next_prev .="Den trang sau"; 
            } 
            else 
            { 
                $next_prev .="<a href=\"".$_SERVER['PHP_SELF']."?mod=loaihang"."&page=".($curpage+1)."\"> Trang sau</a>"; 
            } 
            return $next_prev; 
    } 
}
?>
	